// pages/assess/infomation/index.js
const app = getApp()
const db = wx.cloud.database()
const _ = db.command

Page({

    /**
     * 页面的初始数据
     */
    data: {
        
    },

    getAnmInfo() {
        wx.showLoading({
          title: '加载中',
        })
        let imgnum = Math.floor(Math.random() * 12) + 1001;
        let ananum = Math.floor(Math.random() * (20000 - 10000 + 1) ) + 10000
        let that = this
        this.setData({
            // anmimgPath : app.globalData.anmimgPath,
            pz:app.globalData.anm_name,
            anum: app.globalData.anum,
            analyse: "../../../images/fenxi/"+imgnum+".png",
            ananum: ananum
        })
        wx.cloud.database().collection('analyse').where({
            a1:app.globalData.a1,
            a2:app.globalData.a2,
            a3:app.globalData.a3
        }).get({
            success(resppp){
                if(resppp.data.length != 0){
                    that.setData({
                        anmimgPath: resppp.data[0].imgurl,
                        gw: Math.floor(resppp.data[0].gw),
                        txc: Math.floor(resppp.data[0].txc),
                        tz: Math.floor(resppp.data[0].tz),
                        tg:Math.floor(resppp.data[0].tg),
                        xw:Math.floor(resppp.data[0].xw)
                    })
                    wx.hideLoading({
                      success: (res) => {wx.showToast({
                        title: '成功',
                      })},
                    })
                }else{
                    wx.cloud.database().collection('analyse').get({
                        success(resz){
                            let num = Math.floor(Math.random() * (20) )
                            that.setData({
                                anmimgPath: app.globalData.anmimgPath,
                                gw: Math.floor(resz.data[num].gw),
                                txc: Math.floor(resz.data[num].txc),
                                tz: Math.floor(resz.data[num].tz),
                                tg:Math.floor(resz.data[num].tg),
                                xw:Math.floor(resz.data[num].xw)
                            })
                            wx.hideLoading({
                              success: (res) => {wx.showToast({
                                title: '成功',
                              })},
                            })
                        }
                    })
                }
                
            },fail(err){
                console.log(err)
            }
        })
    },

    toback() {
        wx.reLaunch({
          url: '../index/index',
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getAnmInfo()

    },

})